<template>
	<el-header style="height: auto;">
		<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
	</el-header>
	<el-header>
		<div class="left-panel">
		</div>
		<div class="right-panel">
			<div class="right-panel-search">
				<el-input v-model="search.keyword" placeholder="流程标题" clearable></el-input>
				<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
			</div>
		</div>
	</el-header>
	<el-main class="nopadding">
		<scTable ref="table" :params="{model:'0'}" :apiObj="list.apiObj" row-key="id" stripe remoteSort remoteFilter>
			<el-table-column label="流水号" prop="id" width="100"></el-table-column>
			<el-table-column label="流程标题" prop="flowTitle" width="400" :show-overflow-tooltip="true">
				<template #default="scope">
					<div v-if="scope.row.status=='0'||scope.row.status==undefined" style="position: absolute;"><sc-icon-new/></div>
					{{ scope.row.flowTitle }}
				</template>
			</el-table-column>
			<el-table-column label="抄送人" prop="sendUserName" width="100" align="center"></el-table-column>
			<el-table-column label="紧急程度" prop="urgency" width="100" align="center">
				<template #default="scope">
					<el-tag v-if="scope.row.urgency==0" type="success">一般</el-tag>
					<el-tag v-else-if="scope.row.urgency==1" type="warning">紧急</el-tag>
					<el-tag v-else-if="scope.row.urgency==2" type="danger">加急</el-tag>
					<el-tag v-else type="info">未知</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="抄送时间" prop="createTime" width="150" align="center">
				<template #default="scope">
					<el-tag v-time="scope.row.senToTime" format="yyyy-MM-dd hh:mm"></el-tag>
				</template>
			</el-table-column>
			<el-table-column label="查阅状态" prop="status" width="100" align="center">
				<template #default="scope">
					<el-tag v-if="scope.row.status==1" type="success">已阅</el-tag>
					<el-tag v-else type="info">未阅</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="查阅时间" prop="revTime" width="150" align="center"></el-table-column>
			<el-table-column label="参与人" prop="opUserStr" width="300" align="center" :show-overflow-tooltip="true"></el-table-column>
			<el-table-column label="操作" fixed="right" align="right" width="160">
				<template #default="scope">
					<el-button-group>
						<el-button text type="primary" size="small" @click="readSendToBpm(scope.row, scope.$index)">查阅</el-button>
					</el-button-group>
				</template>
			</el-table-column>
		</scTable>
	</el-main>
</template>
<script>
import scSelectFilter from '@/components/scSelectFilter'
import selectUserDialog from "@/views/module/selectUserDialog";

export default {
	name: 'Bpm End',
	components: {
		scSelectFilter,
		selectUserDialog
	},
	data() {
		return {
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "查阅状态",
					key: "status",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "未阅",
							value: "0"
						},
						{
							label: "已阅",
							value: "1"
						}
					]
				},
				{
					title: "流程分类",
					key: "flowId",
					multiple: true,
					options: [{
						label: "全部",
						value: ""
					}]
				}
			],
			list: {
				apiObj: this.$API.bpm.bpmSendTo.getSendToMeBpmList
			},
			search: {
				model:'0',
				date:'',
				status:'',
				flowId:'',
				keyword: "",
			}
		}
	},
	mounted() {
		this.getSendToBpmFlowList();
	},
	methods: {
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		filterChange(data) {
			this.search.date = data.date;
			this.search.flowId = data.flowId;
			this.search.status = data.status;
			this.$refs.table.upData(this.search)
		},
		async getSendToBpmFlowList() {
			var res = await this.$API.bpm.bpmFlow.getSendToBpmFlowList.get({model:'0'});
			if (res.code == 200) {
				this.filterData[2].options = res.data
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async readSendToBpm(row, index) {
			var res = await this.$API.bpm.bpmSendTo.updateSendToStatus.post({sendToId:row.sendToId});
			if(res.code==200)
			{
				this.$nextTick(() => {
					this.$router.replace({
						path: '/bpm/handle/read',
						query: {
							runId: row.runId
						}
					})
				})
			}else
			{
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
	}
}
</script>
